<?php
/* 商吕视图模型
* @Author: Jerry-chen
* @Date:   2014-07-13 14:21:19
* @Last Modified time: 2014-07-24 12:44:42
* @Last Modified by: Jerry-chen<uranusbill@163.com>
* @ Copyright (c) 2014 http://www.cooldreamer.com All rightsreserved.
*/
class GoodsViewModel extends viewModel
{
	//定义主表
	public $table ='goods';
	//指定关联表信息
	public $view = array(
			'goodsdes'=>array(
				'type'=>INNER_JOIN,
				'on'=>'goods.goodsid=goodsdes.goodsid'
				),
			'goodstime'=>array(
				'type'=>INNER_JOIN,
				'on'=>'goods.goodsid=goodstime.goodsid'

				),
			'goodsattr'=>array(
				'type'=>INNER_JOIN,
				'on'=>'goods.goodsid=goodsattr.goodsid'
				),
			'goodsprice'=>array(
				'type'=>INNER_JOIN,
				'on'=>'goodstime.timeid=goodsprice.goodstimeid'


				),
		);

	/**
	 * [get_all 获得所有数据]
	 * @param  [type] $where [description]
	 * @return [type]        [description]
	 */
	public function get_all($where=null,$in=null,$limit=null,$group=null)
	{
		return $this->where($where)->in($in)->limit($limit)->group($group)->all();
		
	}
	//******************获得分页数据的方法*************
		public function get_page($where=NULL,$field=NULL,$rows=10,$pageNum=3,$pageStyle=2){
			//分页类使用 参数 1.总数，2.每页多少条，3.显示几个页码,4.页码的风格
			//获得数据总数
			$total = $this -> where($where) -> count();
			//实例化分页类
			$page = new Page($total,$rows,$pageNum,$pageStyle);
			//分页显示
			$pageData = $page -> show();
			//获得数据
			$data = $this -> where($where) -> field($field) -> all($page -> limit());
			//将分页压入$data中
			$data['page'] = $pageData;
			return $data;
		}
	/**
	 * [get_one 查找一条数据]
	 * @return [type] [description]
	 */
	public function get_one($where)
	{
		return $this->where($where)->find();
	}
}